#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
typedef struct ListNode
{
	int val;
	struct ListNode* next;
}ListNode;
bool hasCycle(struct ListNode* head) 
{
    ListNode* slow = head;
    ListNode* fast = head;
    while (fast != NULL && fast->next != NULL)
    {
        slow = slow->next;
        fast = fast->next->next;
        if (slow == fast)
            return true;
    }
    return false;
}
void test()
{
    ListNode* head = (ListNode*)malloc(sizeof(ListNode));
    ListNode* h1 = (ListNode*)malloc(sizeof(ListNode));
    ListNode* h2 = (ListNode*)malloc(sizeof(ListNode));
    ListNode* h3 = (ListNode*)malloc(sizeof(ListNode));
    head->val = 3;
    h1->val = 2;
    h2->val = 0;
    h3->val = -4;
    head->next = h1;
    h1->next = h2;
    h2->next = h3;
    h3->next = h1;
    printf("%d\n", hasCycle(head));
}
int main()
{
    test();
	return 0;
}